﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DIS_Client.Helpers;

namespace DIS_Client.MainManagers
{
    public partial class FrmSelectRole : DevComponents.DotNetBar.Office2007Form
    {
        public EventHandler Handler { get; set; }
        private int _selectedRole;

        public FrmSelectRole()
        {
            InitializeComponent();
            LoadManagers();
        }

        public void LoadManagers()
        {
            try
            {
                // Load list all of tinh thanh
                var lst = BusService.Instance.Role_SelectAll();
                for (int i = 0; i < lst.Length; i++)
                {
                    if (lst[i].Name.ToUpper().Contains("MANAGER") && !lst[i].Name.ToUpper().Contains("NATIONAL"))
                    {
                        TreeNode node = new TreeNode(lst[i].ID + " - " + lst[i].Name);
                        node.ImageIndex = 0;
                        treeView1.Nodes.Add(node);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (this._selectedRole != -1)
            {
                this.Handler(this, new TransferSimpleDataEvent(_selectedRole.ToString()));
                Close();
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this._selectedRole = int.Parse(treeView1.SelectedNode.Text.Split('-')[0].Trim());
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            if (_selectedRole != -1)
            {
                this.Handler(this, new TransferSimpleDataEvent(_selectedRole.ToString()));
                Close();
            }
        }
    }
}